//
//  AddNewAddressVC.m
//  LoveTrail
//
//  Created by giantumbrella on 15/6/11.
//  Copyright (c) 2015年 赵娟. All rights reserved.
//
/**
 区域选择 pickview
 数据保存
 上层数据与之之间关系
 */

#import "AddNewAddressVC.h"
#import "CommonMacro.h"
#import "PickerChoseAddressView.h"
@interface AddNewAddressVC ()
@property (nonatomic,strong) UIView *bigBgView;
@property (nonatomic,strong) UILabel *titleLabel;
@property (nonatomic,strong) UITextField *textField;
@property (nonatomic,strong) UIButton *finishButton;
@property (nonatomic,strong) UILabel *messageLabel;
@property (nonatomic,strong) UIButton *choseButton;
@property (nonatomic,strong) PickerChoseAddressView *pickerView;
@end

@implementation AddNewAddressVC

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"编辑收货地址";
    self.view.backgroundColor = UIColorWithRGBA(241, 241, 241, 1);
    self.navigationItem.rightBarButtonItem = nil;
    //创建控件 头部
    [self createBigView];
    //选择地区 弹出视图
    self.pickerView = [[PickerChoseAddressView alloc] init];
    //完成
    self.finishButton = [[UIButton alloc] initWithFrame:CGRectMake(SCREEN_WIDTH*0.25, SCREEN_HEIGHT*0.9, SCREEN_WIDTH*0.5, 40)];
    [self.view addSubview:self.finishButton];
    [self.finishButton setBackgroundImage:[UIImage imageNamed:@"试用详情底部按钮"] forState:UIControlStateNormal];
    [self.finishButton setTitle:@"完  成" forState:UIControlStateNormal];
    [self.finishButton.titleLabel setFont:[UIFont boldSystemFontOfSize:16]];
    self.finishButton.backgroundColor = [UIColor redColor];
    self.finishButton.layer.cornerRadius = 3;
    self.finishButton.clipsToBounds = YES;
    [self.finishButton addTarget:self action:@selector(finishButtonClick) forControlEvents:UIControlEventTouchUpInside];
}

#pragma mark 创建上不大的背景
- (void)createBigView
{
    self.bigBgView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT*0.6)];
    [self.view addSubview:self.bigBgView];
    self.bigBgView.backgroundColor = [UIColor whiteColor];
    
    CGFloat lableX = 0;
    CGFloat labelY = 100;
    CGFloat labelW = 100;
    CGFloat marggin = 10;
    NSArray *titleArray = [[NSArray alloc] init];
    titleArray = @[@"收货人姓名:",@"手机号码:",@"所在区域:",@"地址:",@"邮编:"];
    for (int i=0; i<5; i++) {
         CGFloat labelH = (self.bigBgView.frame.size.height-labelY-marggin*4-50)/5;
        //label
        self.titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(lableX, labelY+(labelH+marggin)*i, labelW, labelH)];
        [self.bigBgView addSubview:self.titleLabel];
        self.titleLabel.text = titleArray[i];
        self.titleLabel.textColor = UIColorWithRGBA(124, 124, 124, 1);
        self.titleLabel.textAlignment = NSTextAlignmentRight;
        //textField
        if (i==2) {
            //装载信息
            self.messageLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.titleLabel.frame.origin.x+self.titleLabel.frame.size.width+3, labelY+(labelH+marggin)*2, labelW*2, labelH)];
            [self.bigBgView addSubview:self.messageLabel];
            self.messageLabel.layer.borderColor = UIColorWithRGBA(218, 218, 218, 1).CGColor;
            self.messageLabel.layer.borderWidth = 1;
            //点击的小箭头
            self.choseButton = [[UIButton alloc] initWithFrame:CGRectMake(200, self.messageLabel.frame.origin.y, 30, labelH)];
            [self.bigBgView addSubview:self.choseButton];
            self.choseButton.backgroundColor = [UIColor redColor];
            [self.choseButton addTarget:self action:@selector(choseAddressButton) forControlEvents:UIControlEventTouchUpInside];

        }else{
        self.textField = [[UITextField alloc] initWithFrame:CGRectMake(self.titleLabel.frame.origin.x+self.titleLabel.frame.size.width+3, labelY+(labelH+marggin)*i, labelW*2, labelH)];
        [self.bigBgView addSubview:self.textField];
        self.textField.backgroundColor = UIColorWithRGBA(238, 238, 238, 1);
        }
    }
}

#pragma mark 选择地区弹出的视图
- (void)choseAddressButton
{
    NSLog( @"address");
    [self.pickerView pickerChooseAddressView];
}

#pragma mark 保存数据 并且返回上一个界面
- (void)finishButtonClick
{
    [self dismissViewControllerAnimated:YES completion:nil];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

@end
